//
// Created by lz on 3/4/21.
//

#ifndef MYWEBLIB_NET_EVENTLOOPTHREAD_H_
#define MYWEBLIB_NET_EVENTLOOPTHREAD_H_

#include "base/Condition.h"
#include "base/Mutex.h"
#include "base/Thread.h"

namespace lzweb
{
	namespace net
	{
		class EventLoop;

		class EventLoopThread : noncopyable
		{
		 public:
			using ThreadInitCallback = std::function<void (EventLoop*)>;

			EventLoopThread(const ThreadInitCallback& cb = ThreadInitCallback(),
				const string& name = string());

			~EventLoopThread();

			EventLoop* startLoop();

		 private:
			void threadFunc();

			EventLoop* loop_ GUARDED_BY(mutex_);
			bool exiting_;
			Thread thread_;
			MutexLock mutex_;
			Condition cond_ GUARDED_BY(mutex_);
			ThreadInitCallback callback_;
		};
	}// namespace net
} // namespace lzweb




#endif //MYWEBLIB_NET_EVENTLOOPTHREAD_H_
